//
//  newTweet.m
//  weibo3
//
//  Created by Tian Wu on 11-4-15.
//  Copyright 2011年 nfsysu. All rights reserved.
//

#import "newDM.h"


@implementation newDM

@synthesize retweeted;

- (NSString *)windowNibName
{
	return @"newDM";
}


- (BOOL)edit:(Status *)startingValues from:(id)sender
{
    

        
    
        
	[NSApp beginSheet:[self window] modalForWindow:[sender window] modalDelegate:nil didEndSelector:nil contextInfo:nil];
    if (startingValues != nil) {
        
        if([[startingValues retweeted_status] text] != nil){
            
            NSString *temp = [NSString stringWithFormat:@"//@%@: %@",[[startingValues user] name],[startingValues text]];
            [text setTitleWithMnemonic:temp];
            self.retweeted = [startingValues retweeted_status];
            
        }
        else{
            
            self.retweeted = startingValues;
            
        }
    }
	[NSApp runModalForWindow:[self window]];
    
	// sheet is up here...
    
	[NSApp endSheet:[self window]];
	[[self window] orderOut:self];
    
    return YES;
}


- (IBAction) sendIt:(id) sender{
    
    NSString *status = [text stringValue];
    
    if ([status length] > 140) {
        NSAlert *alert = [NSAlert alertWithMessageText:@"字数太多了" defaultButton:@"好的" alternateButton:nil otherButton:nil informativeTextWithFormat:@"最多可以输入140字，而您已经输入了%d字噢！",[[text stringValue] length]];
        [alert beginSheetModalForWindow:[self window] modalDelegate:self didEndSelector:nil contextInfo:NULL];
    }
    else if([status length] < 1){
        NSAlert *alert = [NSAlert alertWithMessageText:@"请输入文字" defaultButton:@"好的" alternateButton:nil otherButton:nil informativeTextWithFormat:@"请在白色区域中输入您想要发送的微博！"];
        [alert beginSheetModalForWindow:[self window] modalDelegate:self didEndSelector:nil contextInfo:NULL];
    }
    else{
        
        
        [text setStringValue:@""];
        
        
        if ([self.retweeted text] != nil) {
            [_rootViewController statusRepost:[self.retweeted aid] status:status];
        }
        else{
        }
        
        [NSApp stopModal];
        
        
    }
    
    
    
    
}


- (IBAction) cancel:(id) sender{
    [NSApp stopModal];
}


- (id)initWithWindow:(NSWindow *)window
{
    self = [super initWithWindow:window];
    if (self) {
    }
    
    return self;
}


- (void)dealloc
{
    [super dealloc];
}

- (void)windowDidLoad
{
    [super windowDidLoad];
    // Implement this method to handle any initialization after your window controller's window has been loaded from its nib file.
}

@end
